import time

from selenium import webdriver
from selenium.webdriver.common.by import By
from unittest import TestCase
from ddt import ddt, data, unpack


@ddt
class TestSign(TestCase):
    login_test_data = [
        ['wangwu', '123456', '123456', '度小满理财-登录[内测版]'],
        ['wangwu', '123456', '123456', '个人理财系统注册界面'],
        ['wangwu1', '123456', '1234567', '个人理财系统注册界面'],
        ['wangwu1', '123456', '', '个人理财系统注册界面']
    ]

    @data(*login_test_data)
    @unpack
    def testSign(self, username, password, repassword, expected):
        option = webdriver.ChromeOptions()
        option.add_argument('--headless')
        # 创建谷歌浏览器对象
        driver = webdriver.Chrome(options=option)

        # 窗口最大化
        driver.maximize_window()

        driver.get("http://localhost:90")

        # 点击注册链接
        driver.find_element(By.LINK_TEXT, '还没有账号？去注册').click()

        # 输入用户名
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys(username)
        # time.sleep(1)
        # 输入密码
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys(password)
        # time.sleep(1)
        # 重复密码
        driver.find_element(By.XPATH, '//input[@id="repassword"]').send_keys(repassword)
        # 点击注册按钮
        driver.find_element(By.XPATH, '//button[@id="login_btn"]').click()

        time.sleep(1)

        # 获取实际结果
        # result = driver.find_element(By.TAG_NAME, 'title').text  # .text取出文本数据
        result = driver.title

        # 退出浏览器
        driver.quit()
        self.assertEqual(result, expected)
